from db import db
import datetime

class SegmentationHistory(db.Model):
    __tablename__ = 'segmentation_history'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(255), nullable=False)
    raw_image = db.Column(db.String(255), nullable=False)
    result_image = db.Column(db.String(255), nullable=False)
    area_ratio = db.Column(db.Float, nullable=False)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)
                         
    def __init__(self, username, raw_image, result_image, area_ratio):
        self.username = username
        self.raw_image = raw_image
        self.result_image = result_image
        self.area_ratio = area_ratio

    def to_dict(self):
        return {
            'id': self.id,
            'username': self.username,
            'rawImage': self.raw_image,
            'resultImage': self.result_image,
            'areaRatio': self.area_ratio,
            "createTime": self.create_time.strftime('%Y-%m-%d %H:%M:%S')
        }